<template>
  <div class="dashboard-container">
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              平台用户
            </div>
            <count-to :start-val="0" :end-val="userCount" :duration="userCount" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="message" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              更新通知
            </div>
            <count-to :start-val="0" :end-val="noticeCount" :duration="noticeCount" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="dashboard" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              所属系统
            </div>
            <count-to :start-val="0" :end-val="systemCount" :duration="systemCount" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="example" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              暂未开发
            </div>
            <count-to :start-val="0" :end-val="99999" :duration="99999" class="card-panel-num" />
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="12">
      <el-col :span="6">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>最新动态</span>
          </div>
          <el-timeline class="log">
            <el-timeline-item
              v-for="(log, index) in logList"
              :key="index"
              :color="iconLog(log)"
              :timestamp="log.createTime | dateFormat('MM月DD日 HH:mm')"
            >
              <span v-text="echoLog(log)" />
            </el-timeline-item>
          </el-timeline>
        </el-card>
      </el-col>
      <el-col :span="9">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>平台更新日志</span>
          </div>
          <el-collapse v-model="activeName" accordion>
            <el-collapse-item title="v1.0.1 - 2021-1-5" name="1">
              <div>1.新增通知群定时任务推送模块</div>
              <div>2.新增定时任务日志</div>
              <div>3.新增最近动态记录</div>
              <div>4.其他细节优化</div>
            </el-collapse-item>
            <el-collapse-item title="v1.0.0 - 2021-1-5" name="2">
              <div>1.开发者管理平台前后端分离系统正式发布</div>
            </el-collapse-item>
          </el-collapse>
        </el-card>
      </el-col>
      <el-col :span="9">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>联系信息</span>
          </div>
          <div><i class="el-icon-position" /> 官网：<el-link href="https://www.dapengjiaoyu.com" type="primary" target="_blank">www.dapengjiaoyu.com</el-link></div>
          <div><i class="el-icon-user" /> 联系人：ql</div>
          <div><i class="el-icon-s-claim" /> 投诉邮箱：1224999091@qq.com</div>
          <div />
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { systemCount } from '@/api/system'
import { noticeCount } from '@/api/data/notice'
import { userCount } from '@/api/user'
import { logIndexList } from '@/api/log'
import { mapGetters } from 'vuex'
import CountTo from 'vue-count-to'

export default {
  name: 'Dashboard',
  components: {
    CountTo
  },
  data() {
    return {
      activeName: '1',
      userCount: 0,
      noticeCount: 0,
      systemCount: 0,
      logList: []
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  created() {
    this.count()
  },
  methods: {
    count() {
      userCount().then(response => {
        this.userCount = response.data
      })
      noticeCount().then(response => {
        this.noticeCount = response.data
      })
      systemCount().then(response => {
        this.systemCount = response.data
      })
      logIndexList().then(response => {
        this.logList = response.data
      })
    },
    echoLog(row) {
      if (row.discription === '登录') {
        return row.createByName + ' 登录系统'
      }
      return row.createByName + ' ' + row.discription
    },
    iconLog(row) {
      if (row.discription !== '登录') {
        return '#0bbd87'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.log{
  height: 280px;
  overflow: auto;
}
.el-timeline-item {
  padding-bottom: 10px;
}
::v-deep .el-timeline-item__wrapper{
  top: 0!important;
}
::v-deep .el-timeline-item__timestamp.is-bottom {
  position: absolute;
  left: -110px;
  top: -5px;
  color: #333333;
}
::v-deep .el-timeline {
  padding-left: 120px;
}
.dashboard {
  &-container {
    margin: 30px;
  }
}
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
.el-progress {
  position: relative;
  line-height: 2;
}
</style>
